package com.tanhua.server.service;

import com.tanhua.dubbo.api.QuestionApi;
import com.tanhua.dubbo.pojo.Question;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author TICO
 * @date 2021/6/20 14:59
 */
@Service
public class QuestionService {


    @DubboReference(version = "1.0.0")
    private QuestionApi questionApi;

    public void save(Long userId, String content) {

        Question question = this.questionApi.queryQuestion(userId);

        if(null != question){
            question.setTxt(content);
            this.questionApi.updateById(question);
        }else {
            question = new Question();
            question.setUserId(userId);
            question.setTxt(content);
            question.setCreated(new Date());
            question.setUpdated(question.getCreated());
            this.questionApi.insert(question);
        }
    }
}
